﻿using LPLS.Commons.DBModule;
using LPLS.DBEntities;
using LPLS.DBEntities.ConfigModels.DeviceInfoModels;
using LPLS.DBInterface.ConfigModels.DeviceInfoModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LPLS.DBServices.ConfigModels.DeviceInfoModels
{
    internal class DeviceComponentInfoService : DBBaseService, IDeviceComponentInfoService
    {
        public DeviceComponentInfoService(DBContext dbContext) : base(dbContext)
        {
        }

        public int AddData(DeviceComponentInfo model)
        {
         return   Client.Insertable(model)
                .ExecuteCommand();        
        }

        public int DeleteData(Guid id)
        {
        return    Client.Deleteable<DeviceComponentInfo>()
                .Where(it => it.ID == id)
                .ExecuteCommand();
            
        }

        public List<DeviceComponentInfo> GetData()
        {
            var li= Client.Queryable<DeviceComponentInfo>()
                .ToList();

            InitData(li);
            return li;
        }

        public override void InitDataBaseName()
        {
            DataBaseName = DatabaseEnum.SqliteConfig.ToString();
        }

        public int UpdateData(DeviceComponentInfo model)
        {
         return   Client.Updateable(model)
                
                .ExecuteCommand();
        
        }

        private void InitData(List<DeviceComponentInfo> li) {

            Parallel.For(0, li.Count, i => {

                li[i].ComponentTypeName = li[i].ComponentType.GetDescription();


            });
        
        
        }
    }
}
